﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace TeacherLeftHand.Model
{
    public class TeachingPlan : IDataErrorInfo
    {
        #region Properties
        private int _classLevel;
        private DateTime? _composeDate;
        private DateTime? _teachingDate;
        private string _subject;
        private string _topic;
        private int _topicNo;
        private int _session;
        private int _week;
        private object _objective;
        private object _preparation;
        private List<Activity> _activities;
        //private string _activities;
        private object _note;

        public int ClassLevel
        {
            get
            {
                return _classLevel;
            }
            set
            {
                _classLevel = value;
            }
        }

        public DateTime? ComposeDate
        {
            get { return (DateTime?)_composeDate; }
            set { _composeDate = value; }
        }

        public DateTime? TeachingDate
        {
            get { return (DateTime?)_teachingDate; }
            set { _teachingDate = value; }
        }

        public string Subject
        {
            get { return _subject; }
            set { _subject = value; }
        }

        public string Topic
        {
            get { return _topic; }
            set { _topic = value; }
        }

        public int Session
        {
            get { return _session; }
            set { _session = value; }
        }

        public int Week
        {
            get { return _week; }
            set { _week = value; }
        }

        public object Objective
        {
            get { return _objective; }
            set { _objective = value; }
        }

        public object Preparation
        {
            get { return _preparation; }
            set { _preparation = value; }
        }

        //public List<Activity> Activities
        //{
        //    get { return _activities; }
        //    set { _activities = value; }
        //}

        public List<Activity> Activities
        {
            get { return _activities; }
            set { _activities = value; }
        }

        public object Note
        {
            get { return _note; }
            set { _note = value; }
        }

        public int TopicNo
        {
            get { return _topicNo; }
            set { _topicNo = value; }
        }

        #endregion

        #region Constructor
        public TeachingPlan(int classLevel = 1, string subject = null, int topicNo = 1, string topic = null, int session = 1, int week = 1, object objectives = null, object preparation = null, List<Activity> activities = null, object note = null)
        {
            ClassLevel = classLevel;
            ComposeDate = DateTime.Today;
            TeachingDate = DateTime.Today;
            Subject = subject;
            TopicNo = topicNo;
            Topic = topic;
            Session = session;
            Week = week;
            Objective = objectives;
            Preparation = preparation;
            Activities = activities;
            Note = note;
        }
        #endregion

        #region Implementation of IDataErrorInfo

        /// <summary>
        /// Gets the error message for the property with the given name.
        /// </summary>
        /// <returns>
        /// The error message for the property. The default is an empty string ("").
        /// </returns>
        /// <param name="columnName">The name of the property whose error message to get. </param>
        public string this[string columnName]
        {
            get
            {
                string msg = string.Empty;
                switch (columnName)
                {
                    // class level is required field
                    case "ClassLevel":
                        if (ClassLevel < 1 || ClassLevel > 5)
                        {
                            msg = "Required field";
                        }
                        break;

                    // subject is required field
                    case "Subject":
                        if (string.IsNullOrEmpty(Subject))
                        {
                            msg = "Required field";
                        }
                        break;

                    // topic is required field
                    case "Topic":
                        if (string.IsNullOrEmpty(Topic))
                        {
                            msg = "Required field";
                        }
                        break;

                    // session is required and must be a positive number
                    case "Session":
                        if (Session <= 0)
                        {
                            msg = "Session cannot be less than zero";
                        }
                        break;

                    // optional fields
                    case "Activities":
                    case "ComposeDate":
                    case "TeachingDate":
                    case "TopicNo":
                    case "Note":
                    case "Objective":
                    case "Preparation":
                        break;
                    default: throw new ArgumentException(
                        "Unrecognized property: " + columnName);
                }
                return msg;
            }
        }

        /// <summary>
        /// Gets an error message indicating what is wrong with this object.
        /// </summary>
        /// <returns>
        /// An error message indicating what is wrong with this object. The default is an empty string ("").
        /// </returns>
        public string Error
        {
            get { return string.Empty; }
        }

        #endregion
    }
}
